//
//  SDTableViewCell.m
//  SuperDoctor
//
//  Created by 陶宏路 on 16/7/6.
//  Copyright © 2016年 SD. All rights reserved.
//

#import "SDTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "SDFocusModel.h"

@interface SDTableViewCell ()

@property (nonatomic,strong) UIImageView * docImageView;
@property (nonatomic,strong) UILabel * fNameLable;
@property (nonatomic,strong) UILabel * sNameLable;
@property (nonatomic,strong) UILabel * mainLable;
@property (nonatomic,strong) UIImageView * buttomImage;
@property (nonatomic,strong) UILabel * sd;
@property (nonatomic,strong) UILabel * numLable;
@property (nonatomic,strong) UIButton * flowButton;
@property (nonatomic,strong) UIButton * plusButton;
@property (nonatomic,strong) UIButton * strButton;
@end
@implementation SDTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
        UIImageView * imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
        self.docImageView = imageView;
        [self addSubview:imageView];
        
        
        UILabel * fNameLable = [[UILabel alloc]init];
        [self addSubview:fNameLable];
        self.fNameLable = fNameLable;
        
        UILabel * sNameLable = [[UILabel alloc]init];
        [self addSubview:sNameLable];
        self.sNameLable = sNameLable;
        
        UILabel * mainLable = [[UILabel alloc]init];
        [self addSubview:mainLable];
        self.mainLable = mainLable;
        
        UIImageView * buttomImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pipeidu"]];
        self.buttomImage = buttomImage;
        [self addSubview:buttomImage];
        
        UILabel * sd = [[UILabel alloc]init];
        [self.buttomImage addSubview:sd];
        self.sd = sd;
        
        UILabel * numLable = [[UILabel alloc]init];
        self.numLable = numLable;
        [self.buttomImage addSubview:numLable];
        
        UIButton * flowButton = [[UIButton alloc]init];
        self.flowButton = flowButton;
        [self addSubview:flowButton];
        
        UIButton * plusButton = [[UIButton alloc]init];
        self.plusButton = plusButton;
        [self addSubview:plusButton];

        UIButton * strButton = [[UIButton alloc]init];
        self.strButton = strButton;
        [self addSubview:strButton];

        
        [self setUpUI];
    }
    return self;
}

-(void)setUpUI{
    
    self.fNameLable.font = [UIFont systemFontOfSize:18];
    self.sNameLable.font = [UIFont systemFontOfSize:16];
    self.sNameLable.textColor = [UIColor grayColor];
    self.mainLable.font = [UIFont systemFontOfSize:16];
    self.mainLable.textColor = [UIColor grayColor];
    self.sd.font = [UIFont systemFontOfSize:12];
    self.sd.textAlignment = NSTextAlignmentCenter;
    self.numLable.font = [UIFont systemFontOfSize:12];
    self.numLable.textAlignment = NSTextAlignmentCenter;
    self.sd.textColor = [UIColor whiteColor];
    self.numLable.textColor = [UIColor whiteColor];
    [self.plusButton setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
    [self.flowButton setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
    [self.strButton setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];

}

-(void)layoutSubviews{
   
    [self.docImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).offset(10);
    
        make.left.mas_equalTo(self.mas_left).offset(10);
        
        make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
        
        make.width.mas_equalTo(self.docImageView.mas_height);
        
        
    }];
    
    [self.fNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.docImageView.mas_top);
        make.left.mas_equalTo(self.docImageView.mas_right).offset(10);
        
    }];
    
    [self.sNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.fNameLable.mas_centerY);
        make.left.mas_equalTo(self.fNameLable.mas_right).offset(5);
        
    }];
    
    [self.mainLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.mas_equalTo(self.fNameLable.mas_leading).offset(-2);
        
        make.top.mas_equalTo(self.fNameLable.mas_bottom).offset(10);
        
        make.right.mas_equalTo(self.mas_right).offset(5);
        
    }];
    
    [self.buttomImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top).offset(-5);
        
        make.right.mas_equalTo(self.mas_right).offset(-20);
        
        make.width.mas_equalTo(40);
        
        make.height.mas_equalTo(55);
    }];
    
    [self.sd mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.buttomImage.mas_top).offset(10);
        make.left.mas_equalTo(self.buttomImage.mas_left).offset(2);
        make.right.mas_equalTo(self.buttomImage.mas_right).offset(-2);
        
    }];
    [self.numLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.sd.mas_bottom).offset(5);
        
        make.left.mas_equalTo(self.sd.mas_left);
        
        make.right.mas_equalTo(self.sd.mas_right);
    }];
    
    [self.plusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.fNameLable.mas_leading);
        make.top.mas_equalTo(self.mainLable.mas_bottom).offset(10);
    }];
    
    [self.flowButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.plusButton);
        make.left.mas_equalTo(self.plusButton.mas_right).offset(10);
    }];
    
    [self.strButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.flowButton);
        make.left.mas_equalTo(self.flowButton.mas_right).offset(10);
    }];
}

-(void)setModel:(SDFocusModel *)model{
    
    _model = model;
    
//    [self.docImageView sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait]];
    
    self.fNameLable.text = model.doctor_name;
    self.sNameLable.text = model.doctor_title_name;
    self.mainLable.text = model.doctor_hospital_name;
    self.sd.text = @"匹配度";
    self.numLable.text = model.accuracy;

    [self setButtonWith:self.plusButton andModel:model.operation_count];
    [self setButtonWith:self.flowButton andModel:model.flower];
    [self setButtonWith:self.strButton andModel:model.banner];
    
}

-(void)setButtonWith:(UIButton * )button andModel:(NSInteger)model{
    
    [button setTitle:[NSString stringWithFormat:@"  %zd",model] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button setTitleColor:kThemeColor forState:UIControlStateNormal];
    

}
@end
